<?php
/**
 * @file rightnowfashionwear.php
 * @author LinLin
 * @date 2017年3月17日 上午11:59:47
 * @brief 首页rightnow 右下方 星装备 手动自动
 */
namespace haibao\cms\business\control\pc\index;
use \haibao\cms\business\control\pc\entity\ArticleEntity;
use haibao\frame\data\query\Condition;

class FashionWearController extends IndexController{

    public function __construct($updateTime = null,$controlId,$isPublish){

        parent::__construct($updateTime,$controlId,$isPublish);
    }
    
    public function displayTemplateHtml(){
    
        $controlData = $this->getParameter(self::$CONTROL_DATA);
        $content = $this->getParameter(self::$CONTROL_CONTENT);
        $parameters = array();
        if($controlData['auto']){
			foreach($controlData['auto'] as $data){
				$parameterValue = json_decode($data['ParameterValue']);
				array_push($parameters,$parameterValue);
			}
			if($parameters){
			     $parameters = $parameters[0];
		         $fashionWearArr['Title'] = $parameters->title;
		         $fashionWearArr['Url'] = $parameters->url;
		         $fashionWearArr['SharePicUrl'] = $parameters->imgUrl;
			}
		} 
		if(empty($fashionWearArr) && empty($parameters)){
		   $fashionWearArr = $this->getNewFashionWear();
		}
		$this->assign('fashionWearArr', $fashionWearArr);
        $path = $this->generateHtmlPath(__CLASS__);
        $isNewHtml = $this->generateHtml($path,$content);
        
        $content = $this->getHtml($path);
        $content = $this->replaceCDNLink($content);
        return $content;
    }
    
    public function getNewFashionWear(){
        $fashionWearId = \haibao\cms\business\fashionwear\FashionWear::getNewFashionWear();
        $fashionWearArr = array();
        $fashionWearFilter = new \haibao\cms\model\filter\fashionwear\FashionWear();
        $fashionWearFilter->select(array(
            $fashionWearFilter::CONDITION_FIELD_NAME_ID,
            $fashionWearFilter::CONDITION_FIELD_NAME_TITLE,
            $fashionWearFilter::CONDITION_FIELD_NAME_SHAREPICURL,
        ))->limit(1);
        $fashionWearFilter->order($fashionWearFilter::CONDITION_FIELD_NAME_UPDATETIME,false);
        $fashionWearFilter->where($fashionWearFilter::CONDITION_FIELD_NAME_SHAREPICURL,Condition::CONDITION_NOTEQUAL,'');
        $fashionWearFilter->where($fashionWearFilter::CONDITION_FIELD_NAME_STATUS,Condition::CONDITION_EQUAL,\haibao\cms\model\data\fashionwear\FashionWear::STATUS_ENABLE);
        $fashionWearFilter->where($fashionWearFilter::CONDITION_FIELD_NAME_PUBLISHED,Condition::CONDITION_EQUAL,\haibao\cms\model\data\fashionwear\FashionWear::PUBLISHED_YES);
        if($fashionWearId){
            $fashionWearFilter->where($fashionWearFilter::CONDITION_FIELD_NAME_ID,Condition::CONDITION_EQUAL,$fashionWearId);
        }
        $result = \haibao\cms\business\fashionwear\FashionWear::getOneByFilter($fashionWearFilter);
        if($result){
            $articleContent = new \haibao\cms\business\control\Base();
            $fashionWearArr['SharePicUrl'] = $articleContent->getImageLink($result->SharePicUrl, 300, 300, 100, 0);
            $fashionWearArr['Url'] = \haibao\classlibrary\Config::getConfig(\haibao\classlibrary\Config::CLASSLIBRARY_CONFIG_HOST_PIC).'/fashionwear.html';//\haibao\classlibrary\Config::getConfig(\haibao\classlibrary\Config::CLASSLIBRARY_CONFIG_HOST_PIC).'/fashionimage/'.$result->Id.'.html';
            $fashionWearArr['Title'] = $result->Title;
        }
        return $fashionWearArr;
    }
}